winsafe\ole\com_interfaces/
imoniker.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::kernel::privs::*;
6use crate::ole::{privs::*, vts::*};
7use crate::prelude::*;
8
9com_interface! { IMoniker: "0000000f-0000-0000-c000-000000000046";
10	/// [`IMoniker`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nn-objidl-imoniker)
11	/// COM interface.
12	///
13	/// Automatically calls
14	/// [`Release`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-release)
15	/// when the object goes out of scope.
16}
17
18impl ole_IPersist for IMoniker {}
19impl ole_IPersistStream for IMoniker {}
20impl ole_IMoniker for IMoniker {}
21
22/// This trait is enabled with the `ole` feature, and provides methods for
23/// [`IMoniker`](crate::IMoniker).
24///
25/// Prefer importing this trait through the prelude:
26///
27/// ```no_run
28/// use winsafe::prelude::*;
29/// ```
30pub trait ole_IMoniker: ole_IPersistStream {
31	/// [`IMoniker::BindToObject`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-bindtoobject)
32	/// method.
33	#[must_use]
34	fn BindToObject<T>(
35		&self,
36		bind_ctx: &impl ole_IBindCtx,
37		moniker_to_left: Option<&impl ole_IMoniker>,
38	) -> HrResult<T>
39	where
40		T: ole_IUnknown,
41	{
42		let mut queried = unsafe { T::null() };
43		ok_to_hrresult(unsafe {
44			(vt::<IMonikerVT>(self).BindToObject)(
45				self.ptr(),
46				bind_ctx.ptr(),
47				moniker_to_left.map_or(std::ptr::null_mut(), |m| m.ptr()),
48				pcvoid(&T::IID),
49				queried.as_mut(),
50			)
51		})
52		.map(|_| queried)
53	}
54
55	/// [`IMoniker::BindToStorage`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-bindtostorage)
56	/// method.
57	#[must_use]
58	fn BindToStorage<T>(
59		&self,
60		bind_ctx: &impl ole_IBindCtx,
61		moniker_to_left: Option<&impl ole_IMoniker>,
62	) -> HrResult<T>
63	where
64		T: ole_IUnknown,
65	{
66		let mut queried = unsafe { T::null() };
67		ok_to_hrresult(unsafe {
68			(vt::<IMonikerVT>(self).BindToStorage)(
69				self.ptr(),
70				bind_ctx.ptr(),
71				moniker_to_left.map_or(std::ptr::null_mut(), |m| m.ptr()),
72				pcvoid(&T::IID),
73				queried.as_mut(),
74			)
75		})
76		.map(|_| queried)
77	}
78
79	/// [`IMoniker::CommonPrefixWith`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-commonprefixwith)
80	/// method.
81	#[must_use]
82	fn CommonPrefixWith(&self, other: &impl ole_IMoniker) -> HrResult<IMoniker> {
83		let mut queried = unsafe { IMoniker::null() };
84		ok_to_hrresult(unsafe {
85			(vt::<IMonikerVT>(self).CommonPrefixWith)(self.ptr(), other.ptr(), queried.as_mut())
86		})
87		.map(|_| queried)
88	}
89
90	/// [`IMoniker::ComposeWith`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-composewith)
91	/// method.
92	#[must_use]
93	fn ComposeWith(
94		&self,
95		moniker_to_right: &impl ole_IMoniker,
96		only_if_not_generic: bool,
97	) -> HrResult<IMoniker> {
98		let mut queried = unsafe { IMoniker::null() };
99		ok_to_hrresult(unsafe {
100			(vt::<IMonikerVT>(self).ComposeWith)(
101				self.ptr(),
102				moniker_to_right.ptr(),
103				only_if_not_generic as _,
104				queried.as_mut(),
105			)
106		})
107		.map(|_| queried)
108	}
109
110	/// [`IMoniker::Enum`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-enum)
111	/// method.
112	#[must_use]
113	fn Enum(&self, forward: bool) -> HrResult<IMoniker> {
114		let mut queried = unsafe { IMoniker::null() };
115		ok_to_hrresult(unsafe {
116			(vt::<IMonikerVT>(self).Enum)(self.ptr(), forward as _, queried.as_mut())
117		})
118		.map(|_| queried)
119	}
120
121	/// [`IMoniker::GetDisplayName`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-getdisplayname)
122	/// method.
123	#[must_use]
124	fn GetDisplayName(
125		&self,
126		bind_ctx: &impl ole_IBindCtx,
127		moniker_to_left: Option<&impl ole_IMoniker>,
128	) -> HrResult<String> {
129		let mut pstr = std::ptr::null_mut::<u16>();
130		ok_to_hrresult(unsafe {
131			(vt::<IMonikerVT>(self).GetDisplayName)(
132				self.ptr(),
133				bind_ctx.ptr(),
134				moniker_to_left.map_or(std::ptr::null_mut(), |m| m.ptr()),
135				&mut pstr,
136			)
137		})
138		.map(|_| htaskmem_ptr_to_str(pstr))
139	}
140
141	/// [`IMoniker::GetTimeOfLastChange`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-gettimeoflastchange)
142	/// method.
143	#[must_use]
144	fn GetTimeOfLastChange(
145		&self,
146		bind_ctx: &impl ole_IBindCtx,
147		moniker_to_left: Option<&impl ole_IMoniker>,
148	) -> HrResult<FILETIME> {
149		let mut ft = FILETIME::default();
150		ok_to_hrresult(unsafe {
151			(vt::<IMonikerVT>(self).GetTimeOfLastChange)(
152				self.ptr(),
153				bind_ctx.ptr(),
154				moniker_to_left.map_or(std::ptr::null_mut(), |m| m.ptr()),
155				pvoid(&mut ft),
156			)
157		})
158		.map(|_| ft)
159	}
160
161	/// [`IMoniker::Hash`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-hash)
162	/// method.
163	#[must_use]
164	fn Hash(&self) -> HrResult<u32> {
165		let mut hash = 0u32;
166		ok_to_hrresult(unsafe { (vt::<IMonikerVT>(self).Hash)(self.ptr(), &mut hash) })
167			.map(|_| hash)
168	}
169
170	fn_com_interface_get! { Inverse: IMonikerVT => IMoniker;
171		/// [`IMoniker::Inverse`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-inverse)
172		/// method.
173	}
174
175	/// [`IMoniker::IsEqual`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-isequal)
176	/// method.
177	#[must_use]
178	fn IsEqual(&self, other_moniker: &impl ole_IMoniker) -> HrResult<bool> {
179		okfalse_to_hrresult(unsafe {
180			(vt::<IMonikerVT>(self).IsEqual)(self.ptr(), other_moniker.ptr())
181		})
182	}
183
184	/// [`IMoniker::IsRunning`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-isrunning)
185	/// method.
186	#[must_use]
187	fn IsRunning(
188		&self,
189		bind_ctx: &impl ole_IBindCtx,
190		moniker_to_left: Option<&impl ole_IMoniker>,
191		moniker_newly_running: Option<&impl ole_IMoniker>,
192	) -> HrResult<bool> {
193		okfalse_to_hrresult(unsafe {
194			(vt::<IMonikerVT>(self).IsRunning)(
195				self.ptr(),
196				bind_ctx.ptr(),
197				moniker_to_left.map_or(std::ptr::null_mut(), |m| m.ptr()),
198				moniker_newly_running.map_or(std::ptr::null_mut(), |m| m.ptr()),
199			)
200		})
201	}
202
203	/// [`IMoniker::IsSystemMoniker](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-issystemmoniker)
204	/// method.
205	#[must_use]
206	fn IsSystemMoniker(&self) -> HrResult<(bool, co::MKSYS)> {
207		let mut mksys = co::MKSYS::default();
208		okfalse_to_hrresult(unsafe {
209			(vt::<IMonikerVT>(self).IsSystemMoniker)(self.ptr(), mksys.as_mut())
210		})
211		.map(|b| (b, mksys))
212	}
213
214	/// [`IMoniker::ParseDisplayName`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-parsedisplayname)
215	/// method.
216	#[must_use]
217	fn ParseDisplayName(
218		&self,
219		bind_ctx: &impl ole_IBindCtx,
220		moniker_to_left: &impl ole_IMoniker,
221		display_name: &str,
222	) -> HrResult<(u32, IMoniker)> {
223		let mut ch_eaten = 0u32;
224		let mut queried = unsafe { IMoniker::null() };
225
226		ok_to_hrresult(unsafe {
227			(vt::<IMonikerVT>(self).ParseDisplayName)(
228				self.ptr(),
229				bind_ctx.ptr(),
230				moniker_to_left.ptr(),
231				WString::from_str(display_name).as_ptr(),
232				&mut ch_eaten,
233				queried.as_mut(),
234			)
235		})
236		.map(|_| (ch_eaten, queried))
237	}
238
239	/// [`IMoniker::Reduce`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-reduce)
240	/// method.
241	///
242	/// Returns the moniker to the left, and the reduced moniker, respectively.
243	#[must_use]
244	fn Reduce(
245		&self,
246		bind_ctx: &impl ole_IBindCtx,
247		reduce_how_far: co::MKRREDUCE,
248	) -> HrResult<(IMoniker, IMoniker)> {
249		let (mut queried, mut queried2) = unsafe { (IMoniker::null(), IMoniker::null()) };
250
251		ok_to_hrresult(unsafe {
252			(vt::<IMonikerVT>(self).Reduce)(
253				self.ptr(),
254				bind_ctx.ptr(),
255				reduce_how_far.raw(),
256				queried.as_mut(),
257				queried2.as_mut(),
258			)
259		})
260		.map(|_| (queried, queried2))
261	}
262
263	/// [`IMoniker::RelativePathTo`](https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-imoniker-relativepathto)
264	/// method.
265	#[must_use]
266	fn RelativePathTo(&self, other_moniker: &impl ole_IMoniker) -> HrResult<IMoniker> {
267		let mut queried = unsafe { IMoniker::null() };
268		ok_to_hrresult(unsafe {
269			(vt::<IMonikerVT>(self).RelativePathTo)(
270				self.ptr(),
271				other_moniker.ptr(),
272				queried.as_mut(),
273			)
274		})
275		.map(|_| queried)
276	}
277}